package com.fanco.learn_datastruct_leetcode.juc;/**
 * @author qiaowang 2021/8/18
 */

import java.util.concurrent.CountDownLatch;

/**
 * @author fanco
 * @Desc 描述
 * CountDownLatch Demo 实现 秦灭六国（六个线程） 再走主线程
 */
public class CountDownLatchDemo {

    public static void main(String[] args) {
        CountDownLatch countDownLatch = new CountDownLatch(6);

        for (int i = 0; i < 6; i++) {
            new Thread(() -> {
                System.out.println(Thread.currentThread().getName() + " 线程启动");
                countDownLatch.countDown();
            }, "线程" + i).start();
        }

        try {
            countDownLatch.await();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        System.out.println(Thread.currentThread().getName() + "\t" + "六国灭完了 开始统一");
    }
}
